package com.sumfun.blog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sumfun.blog.mapper.TagMapper;
import com.sumfun.blog.model.domain.Tag;
import com.sumfun.blog.service.TagService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* @author 17337
* @description 针对表【tag(标签 )】的数据库操作Service实现
* @createDate 2024-04-29 22:35:05
*/
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {


    @Override
    public List<String> getTagNamesByIdList(List<Long> tagIdList) {
        if(tagIdList == null) {
            return new ArrayList<>();
        }
        return tagIdList.stream()
                .map(tagId -> Optional.ofNullable(this.getById(tagId))
                        .map(Tag::getTagName)
                        .orElse("Unknown"))  // 或者其他默认值
                .collect(Collectors.toList());
    }
}




